package p0;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author pengjz <br>
 * @version <br>
 * @name Leetcode_14 <br>
 * @date 2020/5/30 0:42<br>
 */
public class Leetcode_17 {
    public List<String> letterCombinations(String digits) {
        if (digits == null || digits.length() == 0) {
            return new ArrayList<>();
        }
        List<List<String>> listList = new ArrayList<>();
        for (char c : digits.toCharArray()) {
            List<String> list;
            if (listList.size() == 0) {
                list = new ArrayList<>(getChar(c));
            } else {
                list = new ArrayList<>();
                for (String s0 : listList.get(listList.size() - 1)) {
                    for (String s1 : getChar(c)) {
                        list.add(s0 + s1);
                    }
                }
            }
            listList.add(list);
        }
        return listList.get(listList.size() - 1);
    }

    public List<String> getChar(char c) {
        switch (c) {
            case '2':
                return Arrays.asList("a", "b", "c");
            case '3':
                return Arrays.asList("d", "e", "f");
            case '4':
                return Arrays.asList("g", "h", "i");
            case '5':
                return Arrays.asList("j", "k", "l");
            case '6':
                return Arrays.asList("m", "n", "o");
            case '7':
                return Arrays.asList("p", "q", "r", "s");
            case '8':
                return Arrays.asList("t", "u", "v");
            case '9':
                return Arrays.asList("w", "x", "y", "z");
            default:
                return new ArrayList<>();
        }
    }


    public static void main(String[] args) {
        Leetcode_17 leetcode = new Leetcode_17();
        System.out.println(leetcode.letterCombinations("23"));
    }
}
